/*************************** Exercise 6 **************************
 * Following Exercise 5, create a new Dog reference
 * and assign it to spot’s object. Test for comparison
 * using == and equals( ) for all references.
 *****************************************************************/

package operators;

import static utils.Print.*;

class Dog{
    public String name;
    public String says;

    public Dog() {
    }

    public Dog(String name, String says) {
        this.name = name;
        this.says = says;
    }

    @Override
    public boolean equals(Object o){
        if((o == null) || (o.getClass() != Dog.class)){
            return false;
        }
        Dog d = (Dog)o;
        if(!d.name.equals(this.name) || !d.says.equals(this.says)){
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 17 * hash + (this.says != null ? this.says.hashCode() : 0);
        return hash;
    }
}


/**
 *
 * @author developer
 */
public class Exercise6 {
     public static void main(String [] args){
        Dog d1 = new Dog("spot", "Ruff!");
        Dog d2 = new Dog("scruffy", "Wurf!");
        print("dog1: name = " + d1.name + " says = " + d1.says);
        print("dog2: name = " + d2.name + " says = " + d2.says);
        Dog d3 = new Dog("spot", "Ruff!");
        print("d1 == d3 - " + (d1 == d3));
        print("d.equals(d3) - " + d1.equals(d3));
    }
}
